#ifndef GRAPHICS__SPATIAL_H_
#define GRAPHICS__SPATIAL_H_

#include "framework.h"
#include "RS.h"
#include "Renderer.h"

using namespace poly;

namespace graphics
{

/*****************
Class Spatial

*This class defines basic structure of the scene graph element
*float44 World should NOT be modified if there is not a good reason to do so. (Should be automated in the derived
classes)
*Local can be modified manually.
******************/

class Renderer;

class Spatial
{
public:
	float44 World;
	float44 Local;

	Spatial();
	virtual ~Spatial(){};
 
	/**
	 * @return Parent of the spatial
	 */
	Spatial*	getParent();

	/**
	 * Sets the parent of the spatial to the given value
	 */
	void		setParent(Spatial*);

	/**
	 * Call this whenever an update to the geometric state 
	 * (Local coordinate modification to a Node or Geometry) is done.
	 */
	void UpdateGS(float dt);

	/**
	 * Internal call.
	 */
	virtual void UpdateWorldData(float dt);

	/**
	 * Calls Draw(Renderer&) of the Node or Geometry.
	 */
	void onDraw(Renderer&);

	/**
	 * Left to be implemented by derived classes.
	 */
	virtual void Draw(Renderer&){};

	/**
	 * Sets the render state of the Spatial.
	 */
	void						SetRenderState(RS);
	/**
	 * Sets the render state of the Spatial
	 * @param Set of render states.
	 */
	void						SetRenderState(std::vector<RS>);
	/**
	 * Removes the render state from the Spatial if it exists.
	 */
	void						RemoveRenderState(RS);
	/**
	 * @return Set of render states.
	 */
	std::vector<RS>				GetRenderStates();
	/**
	 * @return Alpha Blend render states.
	 */
	RS_AlphaBlend				GetRenderState_AlphaBlend();
	/**
	 * @return Material of the Spatial.
	 */
	RS_Material 				GetRenderState_Material();

private:
	/**
	 * Parent of the spatial
	 */
	Spatial*	m_Parent;

	/**
	 * Render States of the Spatial.
	 */
	std::vector<RS> RenderStates;
	/**
	 * Alpha Blend render states.
	 */
	RS_AlphaBlend	RenderStates_AlphaBlend;
	/**
	 * Material of the Spatial.
	 */
	RS_Material 	RenderStates_Material;
};

}/* namespace graphics */
#endif /*GRAPHICS__SPATIAL_H_*/